package com.lengmomo.games.service.impl;


import com.lengmomo.games.mapper.UserMapper;
import com.lengmomo.games.myutil.UUIDUtil;
import com.lengmomo.games.pojo.po.User;
import com.lengmomo.games.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: lengmomo
 * @create: 2021/9/1
 **/
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getUsersByName(String username) {
        return userMapper.getUsersByName(username);
    }

    /**
     * 注册校验登录名是否唯一
     *
     * @param name
     * @return
     */
    @Override
    public boolean isFirstName(String name) {
        List<User> usersByName = this.getUsersByName(name);
        return usersByName.size() == 0;
    }

    /**
     * 注册
     *
     * @param user
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean register(User user) {
        user.setId(UUIDUtil.get32UUID());
        return userMapper.register(user);
    }

}
